<template>
	<view class="page">
		<uni-card title="危险源详情">
			<view class="detail" v-for="(val, key, index) in detailInfo" :key="key">
				<text class="label">{{ val.name }}:</text>
				<text class="field">{{ val.value }}</text>
			</view>
		</uni-card>
	</view>
</template>

<script>
export default {
	data() {
		return {
			detailInfo: {
				danger_code: { name: '编号', value: '' },
				danger_name: { name: '危险源名称', value: '' },
				danger_dept: { name: '危险源管理主责部门', value: '' },
				danger_major: { name: '重大危险源', value: '' },
				danger_src: { name: '危险源来源', value: '' },
				danger_result: { name: '可能导致的后果', value: '' },
				danger_control_measure_now: { name: '现有风险控制措施', value: '' },
				danger_grade_possibility: { name: '可能性', value: '' },
				danger_grade_severity: { name: '严重性', value: '' },
				danger_grade_value: { name: '风险值', value: '' },
				danger_evaluate_grade: { name: '风险评价分级', value: '' },
				danger_control_measure: { name: '风险控制措施', value: '' },
				rest_danger_possibility: { name: '可能性', value: '' },
				rest_danger_severity: { name: '严重性', value: '' },
				rest_danger_value: { name: '风险值', value: '' },
				rest_danger_evaluate_grade: { name: '风险评价分级', value: '' },
				derive_new_danger_src: { name: '是否衍生新的危险源', value: '' }
			}
		}
	},
	onLoad(options) {
		console.log('detail: ', options)
		this.detailId = options.id || 0

		this.getDangerDetail()
	},
	onReady() {},
	methods: {
		async getDangerDetail() {
			const params = {
				id: this.detailId
			}

			try {
				const res = await uni.$uu.Api.getDangerDetail(params)

				console.log(res)

				if (res.code === 100) {
					Object.entries(this.detailInfo).map(([key, val], index) => {
						this.detailInfo[key].value = Object.values(res.content)[index]
					})
				}
			} catch (err) {
				console.log(err)
			}
		}
	}
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
